// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_INV_STORAGE_CHANGE
// * CreateDate    : 2011/8/16 10:16:40
// * Creater       : CodeSmith
// * LastChangeDate: 2011/8/16 10:16:40
// * LastChanger   : 2011/8/16 10:16:40
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;
using ESOL.Common;

namespace ESOL.Business.Inv
{
/// <summary>
    /// InvStorageChange
    /// </summary>
    public partial class InvStorageChangeBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objInvStorageChangeEntity">Entity</param>
        /// <returns>Entity</returns>
        public static InvStorageChangeEntity GetInvStorageChange(InvStorageChangeEntity objInvStorageChangeEntity)
        {
            return DataAccess.SelectSingle<InvStorageChangeEntity>(objInvStorageChangeEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objInvStorageChangeEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertInvStorageChange(InvStorageChangeEntity objInvStorageChangeEntity)
        {
            return DataAccess.Insert(objInvStorageChangeEntity);
        }

        public static bool InsertInvStorageChange(List<InvStorageChangeEntity> objInvStorageChangeEntityList)
        {
            return DataAccess.Insert(objInvStorageChangeEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objInvStorageChangeEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateInvStorageChange(InvStorageChangeEntity objInvStorageChangeEntity)
        {
            return DataAccess.Update(objInvStorageChangeEntity);
        }

        public static bool UpdateInvStorageChange(List<InvStorageChangeEntity> objInvStorageChangeEntityList)
        {
            return DataAccess.Update<InvStorageChangeEntity>(objInvStorageChangeEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objInvStorageChangeEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteInvStorageChange(InvStorageChangeEntity objInvStorageChangeEntity)
        {
            return DataAccess.Delete(objInvStorageChangeEntity);
        }

        public static bool DeleteInvStorageChange(List<InvStorageChangeEntity> objInvStorageChangeEntityList)
        {
            return DataAccess.Delete<InvStorageChangeEntity>(objInvStorageChangeEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetInvStorageChangeAll()
        {
            return DataAccess.SelectAllDataSet<InvStorageChangeEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<InvStorageChangeEntity> GetInvStorageChangeAllList()
        {
            return DataAccess.SelectAll<InvStorageChangeEntity>();
        }

        public static DataTable GetByCondition(string condition, string orderBy, string product_id,string ChangeType,string OrderType)
        {
            string sql = @"select A.* ,F.PRODUCT_CODE,F.PRODUCT_NAME,C.ORDER_CODE AS IM_CODE,C.ORDER_TYPE AS IM_TYPE,C.RELATED_ORDER AS IM_R_ORDER,E.ORDER_CODE AS DT_CODE,E.ORDER_TYPE AS DT_TYPE,E.RELATED_ORDER AS DT_R_ORDER ,B.REMARK AS IM_REMARK,D.REMARK AS DT_REMARK,G.NAME_CN
                            from INV_STORAGE_CHANGE A
                            left join INV_IMPORT_ITEM B on A.RELATED_ORDER=B.IMPORT_ITEM_ID
                            left join INV_IMPORT_ORDER C on B.IMPORT_ORDER_ID=C.IMPORT_ORDER_ID
                            left join INV_DISPATCH_ITEM D on A.RELATED_ORDER=D.DISPATCH_ITEM_ID
                            left join INV_DISPATCH_ORDER E on D.DISPATCH_ORDER_ID=E.DISPATCH_ORDER_ID
                            left join MST_PRODUCT F on A.PRODUCT_ID=F.PRODUCT_ID
                            left join MST_PERSON G on A.CHANGE_USER=G.PERSON_ID
                            WHERE 1=1
                            AND A.PRODUCT_ID='" + product_id+"'";
            if (string.IsNullOrEmpty(condition) == false)
            {
                sql += condition;
            }
            if (string.IsNullOrEmpty(ChangeType) == false)
            {
                sql += " and A.CHANGE_TYPE ='" + ChangeType + "'";
                if (string.IsNullOrEmpty(OrderType) == false)
                {
                    if (ChangeType.Equals("INVC01"))
                    {
                            sql += " and E.ORDER_TYPE='" + OrderType + "'";
                    }
                    if (ChangeType.Equals("INVC02"))
                    {
                            sql += " and C.ORDER_TYPE='" + OrderType + "'";
                    }
                    
                }
            }
            if (string.IsNullOrEmpty(orderBy) == false)
            {
                sql += " ORDER BY " + orderBy;
            }
            DataSet ds = DataAccess.SelectDataSet(sql);
            if (ds != null && ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            return null;
        }
        #endregion
	}
	
	
}	

